package org.convallaria.system.biz.service;

import java.util.List;
import java.util.Map;

/**
 * 缓存优化服务接口
 * 
 * @author convallaria
 * @since 1.0.0
 */
public interface CacheOptimizationService {

    /**
     * 预热缓存
     */
    void warmupCache();

    /**
     * 预热用户相关缓存
     */
    void warmupUserCache();

    /**
     * 预热权限相关缓存
     */
    void warmupPermissionCache();

    /**
     * 预热配置相关缓存
     */
    void warmupConfigCache();

    /**
     * 清理过期缓存
     */
    void cleanExpiredCache();

    /**
     * 获取缓存统计信息
     * 
     * @return 缓存统计
     */
    CacheStatistics getCacheStatistics();

    /**
     * 优化缓存配置
     */
    void optimizeCacheConfig();

    /**
     * 缓存统计信息
     */
    class CacheStatistics {
        private long totalKeys;
        private long hitCount;
        private long missCount;
        private double hitRate;
        private long memoryUsage;
        private long maxMemory;
        private List<CacheKeyInfo> topKeys;

        public CacheStatistics(long totalKeys, long hitCount, long missCount, 
                             double hitRate, long memoryUsage, long maxMemory,
                             List<CacheKeyInfo> topKeys) {
            this.totalKeys = totalKeys;
            this.hitCount = hitCount;
            this.missCount = missCount;
            this.hitRate = hitRate;
            this.memoryUsage = memoryUsage;
            this.maxMemory = maxMemory;
            this.topKeys = topKeys;
        }

        // Getters
        public long getTotalKeys() { return totalKeys; }
        public long getHitCount() { return hitCount; }
        public long getMissCount() { return missCount; }
        public double getHitRate() { return hitRate; }
        public long getMemoryUsage() { return memoryUsage; }
        public long getMaxMemory() { return maxMemory; }
        public List<CacheKeyInfo> getTopKeys() { return topKeys; }
    }

    /**
     * 缓存键信息
     */
    class CacheKeyInfo {
        private String key;
        private String type;
        private long accessCount;
        private long memorySize;
        private long ttl;

        public CacheKeyInfo(String key, String type, long accessCount, long memorySize, long ttl) {
            this.key = key;
            this.type = type;
            this.accessCount = accessCount;
            this.memorySize = memorySize;
            this.ttl = ttl;
        }

        // Getters
        public String getKey() { return key; }
        public String getType() { return type; }
        public long getAccessCount() { return accessCount; }
        public long getMemorySize() { return memorySize; }
        public long getTtl() { return ttl; }
    }
}
